{	Problem: http://codeforces.ru/problemset/problem/6/B
	Verdict: Accepted
}
uses
        SysUtils, Math;

var
        i,j,n,m,ans:longint;
        a:array[0..110,0..110] of char;
        t:array[char] of boolean; 
        ch,kk:char;
                
begin 
fillchar(a,sizeof(a),0);
readln(n,m,ch,ch);
for i:=1 to n do begin
        for j:=1 to m do
                read(a[i][j]);
        readln;
end;
ans:=0;
fillchar(t,sizeof(t),1);
for kk:='A' to 'Z' do 
        t[kk]:=false;
t[ch]:=true;
for i:=1 to n do
        for j:=1 to m do begin
                if a[i][j]<>ch then continue;
                if not t[a[i-1][j]] then begin
                        inc(ans);
                        t[a[i-1][j]]:=true;
                end;
                if not t[a[i][j-1]] then begin
                        inc(ans);
                        t[a[i][j-1]]:=true;
                end;
                if not t[a[i][j+1]] then begin
                        inc(ans);
                        t[a[i][j+1]]:=true;
                end;
                if not t[a[i+1][j]] then begin
                        inc(ans);
                        t[a[i+1][j]]:=true;
                end;
        end;
write(ans);
end.